package com.citms.aif.config;

import com.citms.aif.RegisterConfig;
import com.citms.aif.util.RegisterUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MicroServiceConfig {

    @Autowired
    RegisterUtils registerUtil;

    @Autowired
    RegisterConfig registerConfig;

    @Bean
    @ConditionalOnProperty(name = "citms.cloud.open", havingValue = "true")
    public MicroServiceRegister microServiceRegister(){
        MicroServiceRegister serviceRegister = new MicroServiceRegister();
        serviceRegister.setRegisterUtils(registerUtil);
        serviceRegister.setRegisterConfig(registerConfig);
        return serviceRegister;
    }

    @Bean
    @ConditionalOnProperty(name = "citms.cloud.open", havingValue = "true")
    public MicroServiceDestroyer microServiceDestroyer(){
        MicroServiceDestroyer serviceDestroyer = new MicroServiceDestroyer();
        serviceDestroyer.setRegisterUtil(registerUtil);
        return serviceDestroyer;
    }
}
